<template>
  <el-table-column
    :prop="col.prop"
    :fixed="isFixed(col.prop)"
    :width="col.prop === 'date' ? 500 : 220"
    :label="col.label"
    v-if="col.isShow"
    align="center"
    :formatter="formatTd"
  >
    <template slot-scope="scope">
      <div
        v-if="
          col.prop == 'name' &&
          (mark == 'networkAllItem' || mark == 'networkStartedItem')
        "
      >
        <span>{{
          scope.row[scope.column.property]
            ? scope.row[scope.column.property]
            : '--（未选择网点）'
        }}</span>
      </div>
      <div v-else>
        <span>{{
          scope.row[scope.column.property] !== 0
            ? scope.row[scope.column.property] || '--'
            : 0
        }}</span>
      </div>
    </template>
    <template v-if="col.children">
      <el-table-column
        v-for="(items, indexs) in activeUser"
        :key="indexs"
        :min-width="
          items.prop === 'industryName' || items.prop === 'investmentName'
            ? 150
            : 200
        "
        :filterField="
          items.prop === 'industryName'
            ? industryNameList
            : false || items.prop === 'investmentName'
            ? investmentNameList
            : false
        "
        :filter-multiple="false"
        :prop="items.prop"
        :column-key="items.prop"
        :label="items.label"
        :formatter="formatTd"
      >
        <template slot-scope="scope">
          <span v-if="scope.column.property == 'areaName'">{{
            scope.row[scope.column.property]
              ? scope.row[scope.column.property]
              : ''
          }}</span>
          <span v-else>{{
            scope.row[scope.column.property] !== 0
              ? scope.row[scope.column.property] || '--'
              : 0
          }}</span>
        </template>
      </el-table-column>
    </template>
  </el-table-column>
</template>

<script>
export default {
  name: 'tjMyColumn',
  props: {
    col: {
      type: Object,
    },
    mark: {
      type: String,
    },
    colArr: {
      type: Array,
    },
  },
  data() {
    return {
      investmentNameList: [
        { value: 'GOV', text: '政府投资' },
        { value: 'GOV_AND_SOCIETY', text: '政府与社会共筹' },
        { value: 'NATIONAL', text: '国企项目' },
        { value: 'NOT_GOV', text: '非政府投资' },
        { value: 'OTHERS', text: '其他工程项目' },
      ],
    }
  },
  computed: {
    activeUser: function () {
      const vm = this
      if (vm.col.children) {
        let users = vm.col.children
        return users.filter(function (user) {
          return user.isShow
        })
      }
    },
    industryNameList: function () {
      const vm = this
      let users = vm.$store.state.industryOptions
      let arr = []
      for (let item of users) {
        let obj = {
          value: '',
          text: '',
        }
        obj.value = item.code
        obj.text = item.name
        arr.push(obj)
      }
      return arr
    },
  },
  methods: {
    isFixed(prop) {
      var arr = []
      for (var i = 0; i < this.colArr.length; i++) {
        arr.push(this.colArr[i].isShow)
      }
      var a = true
      const newArr = arr.filter((x) => x === a)
      if (newArr.length >= 3) {
        return prop === 'date' || prop === 'name'
      }
    },
  },
}
</script>
<style scoped>
/* .el-main .searchTable_main {
  position: relative;
}
.el-table__fixed-left {
  position: absolute;
} */
</style>
